package mi.payment.constants;

import android.content.Context;

import mi.payment.settings.SettlementTransactionOperation;
import mi.payment.settings.TerminalKeyManagementBean;
import mi.payment.utils.SharedPreferencesUtil;
import sunmi.sunmiui.utils.LogUtil;

/**
 * 盛付通参数配置缓存
 *
 * @author Lee64 on 2016/12/29.
 */
public class ParameterConfigCache {

    private static final String KEY_PARAMETER_CONFIG = "key_spt_parameter_config";
    private static ParameterConfigCache instance;
    private ParameterConfig instanceSettings;

    public static ParameterConfigCache getInstance() {
        if (instance == null) {
            instance = new ParameterConfigCache();
        }
        return instance;
    }

    private ParameterConfigCache() {
        instanceSettings = getParameterConfig();
        if (instance == null) {
            instanceSettings = new ParameterConfig();
        }
    }

    public void saveParameterConfig(ParameterConfig info) {
        this.instanceSettings = info;
        SharedPreferencesUtil.saveObj(info, KEY_PARAMETER_CONFIG);
    }

    public ParameterConfig getParameterConfig() {
        if(instanceSettings == null) {
            Object obj = SharedPreferencesUtil.readObj(KEY_PARAMETER_CONFIG);
            if (obj instanceof ParameterConfig) {
                instanceSettings = (ParameterConfig) obj;
            } else {
                instanceSettings = new ParameterConfig();
                saveParameterConfig(instanceSettings);
            }
        }
        return instanceSettings;
    }

    public void saveTerminalNo(String terminalNo) {
        ParameterConfig config = getParameterConfig();
        config.setTerminalNo(terminalNo);
        saveParameterConfig(config);
    }

    public void saveMerchantNo(String merchantNo) {
        ParameterConfig config = getParameterConfig();
        config.setMerchantNo(merchantNo);
        saveParameterConfig(config);
    }

    public void saveMerchantName(String merchantName) {
        ParameterConfig config = getParameterConfig();
        config.setMerchantName(merchantName);
        saveParameterConfig(config);
    }

    public void saveParameterVersion(String parameterVersion){
        ParameterConfig config = getParameterConfig();
        config.setParameterVersion(parameterVersion);
        saveParameterConfig(config);
    }

    public void saveSecurePwd(String securePwd) {
        ParameterConfig config = getParameterConfig();
        config.setSecurePwd(securePwd);
        saveParameterConfig(config);
    }

    public void saveCurrentTime(String currentTime) {
        ParameterConfig config = getParameterConfig();
        config.setCurrentTime(currentTime);
        saveParameterConfig(config);
    }

    public void saveSerialNo(String serialNo) {
        ParameterConfig config = getParameterConfig();
        config.setSerialNo(serialNo);
        saveParameterConfig(config);
    }

    public void saveBatchNo(String batchNo) {
        ParameterConfig config = getParameterConfig();
        config.setBatchNo(batchNo);
        saveParameterConfig(config);
    }

    public void saveMaxReturnGoodAmount(String maxReturnGoodAmount) {
        ParameterConfig config = getParameterConfig();
        config.setMaxReturnGoodAmount(maxReturnGoodAmount);
        saveParameterConfig(config);
    }

    public void saveOpenAndCloseBitmap(String openAndCloseBitmap) {
        ParameterConfig config = getParameterConfig();
        config.setOpenAndCloseBitmap(openAndCloseBitmap);
        saveParameterConfig(config);
    }

    public void saveServerAndPort(String serverAndPort) {
        ParameterConfig config = getParameterConfig();
        config.setServerAndPort(serverAndPort);
        saveParameterConfig(config);
    }

    public void saveTPDU(String tpdu) {
        ParameterConfig config = getParameterConfig();
        config.setTPDU(tpdu);
        saveParameterConfig(config);
    }

    public void saveIsPreCall(String isPreCall) {
        ParameterConfig config = getParameterConfig();
        config.setIsPreCall(isPreCall);
        saveParameterConfig(config);
    }

    public void saveTransactionTimeOut(String transactionTimeOut) {
        ParameterConfig config = getParameterConfig();
        config.setTransactionTimeOut(transactionTimeOut);
        saveParameterConfig(config);
    }

    public void saveTransactionRetryTime(String transactionRetryTime) {
        ParameterConfig config = getParameterConfig();
        config.setTransactionRetryTime(transactionRetryTime);
        saveParameterConfig(config);
    }

    public void saveOutsideNumber(String outsideNumber) {
        ParameterConfig config = getParameterConfig();
        config.setOutsideNumber(outsideNumber);
        saveParameterConfig(config);
    }

    public void saveCenterTransactionNumber1(String centerTransactionNumber1) {
        ParameterConfig config = getParameterConfig();
        config.setCenterTransactionNumber1(centerTransactionNumber1);
        saveParameterConfig(config);
    }

    public void saveCenterTransactionNumber2(String centerTransactionNumber2) {
        ParameterConfig config = getParameterConfig();
        config.setCenterTransactionNumber2(centerTransactionNumber2);
        saveParameterConfig(config);
    }

    public void saveCenterTransactionNumber3(String centerTransactionNumber3) {
        ParameterConfig config = getParameterConfig();
        config.setCenterTransactionNumber3(centerTransactionNumber3);
        saveParameterConfig(config);
    }

    public void saveShieldSettings(String shieldSettings) {
        ParameterConfig config = getParameterConfig();
        config.setShieldSettings(shieldSettings);
        saveParameterConfig(config);
    }

    public void saveCorrectRetryTime(String correctRetryTime) {
        ParameterConfig config = getParameterConfig();
        config.setCorrectRetryTime(correctRetryTime);
        saveParameterConfig(config);
    }

    public void savePrintTime(String printTime) {
        ParameterConfig config = getParameterConfig();
        config.setPrintTime(printTime);
        saveParameterConfig(config);
    }

    public void saveMaxTransactionTime(String maxTransactionTime) {
        ParameterConfig config = getParameterConfig();
        config.setMaxTransactionTime(maxTransactionTime);
        saveParameterConfig(config);
    }

    public void saveSignRemark(String signRemark) {
        ParameterConfig config = getParameterConfig();
        config.setSignRemark(signRemark);
        saveParameterConfig(config);
    }

    public void saveElectronicCashTime(String electronicCashTime) {
        ParameterConfig config = getParameterConfig();
        config.setElectronicCashTime(electronicCashTime);
        saveParameterConfig(config);
    }

    public void saveIsShowLogo(String isShowLogo) {
        ParameterConfig config = getParameterConfig();
        config.setIsShowLogo(isShowLogo);
        saveParameterConfig(config);
    }

    public void savePrintTopText(String printTopText) {
        ParameterConfig config = getParameterConfig();
        config.setPrintTopText(printTopText);
        saveParameterConfig(config);
    }

    public void savePrintQRScan(String printQRScan) {
        ParameterConfig config = getParameterConfig();
        config.setPrintQRScan(printQRScan);
        saveParameterConfig(config);
    }

    public void savePrintBottomText(String printBottomText) {
        ParameterConfig config = getParameterConfig();
        config.setPrintBottomText(printBottomText);
        saveParameterConfig(config);
    }

    public void saveTransactionControl(String transactionControl) {
        ParameterConfig config = getParameterConfig();
        config.setTransactionControl(transactionControl);
        saveParameterConfig(config);
    }
}
